#### 稍微复杂一点，买苹果和橘子
from mul_layer import  MulLayer
from add_layer import AddLayer

apple = 100  # 苹果单价
apple_num = 2  # 苹果数量
orange = 150  # 橘子单价
orange_num = 3  # 橘子数量
tax = 1.1  # 消费税

# layer
mul_apple_layer = MulLayer()
mul_orange_layer = MulLayer()
add_appleWihtorange_layer = AddLayer()
mul_tax_layer = MulLayer()

# forward
apple_price = mul_apple_layer.forward(apple, apple_num)
orange_price = mul_orange_layer.forward(orange, orange_num)
appleWithorange_price = add_appleWihtorange_layer.forward(apple_price, orange_price)
price = mul_tax_layer.forward(appleWithorange_price, tax)
print(price)  # 715

# backward
dprice = 1
dappleWithorange_price, dtax = mul_tax_layer.backward(dprice)
dapple_price, dorange_price = add_appleWihtorange_layer.backward(dappleWithorange_price)
dapple, dapple_num = mul_apple_layer.backward(dapple_price)
dorange, dorange_num = mul_orange_layer.backward(dorange_price)
print(dapple_num, dapple, dorange, dorange_num, dtax)  # 110, 2.2, 3.3, 165, 650
